/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package service.enumerations;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author chapmand
 */
public enum Units {
	/** 0 */
	OTHER(0),
	/** 1 */
	EA(1),
	/** 10 */
	VOL_ML(10),
	/** 15 */
	VOL_L(15),
	/** 20 */
	VOL_OZ(20),
	/** 25 */
	VOL_GAL(25),
        /** 30 */
        VOL_BBL(30),
	/** 100 */
	MASS_UG(100),
	/** 105 */
	MASS_G(105),
	/** 110 */
	MASS_KG(110),
        /** 115 */
        MASS_OZ(115),
        /** 120 */
        MASS_LBS(120);

	private int unit;

	Units(final int unit) {
		this.unit = unit;
	}

	public int getUnit() {
		return unit;
	}

	public static Units getUnit(final String unit) {
		return getUnit(Integer.parseInt(unit));
	}

	public static Units getUnit(final int unit) {

		switch (unit) {
                case 0:
                        return OTHER;
                case 1:
                        return EA;
		case 10:
			return VOL_ML;
		case 15:
			return VOL_L;
		case 20:
			return VOL_OZ;
		case 25:
			return VOL_GAL;
                case 30:
                        return VOL_BBL;
		case 100:
			return MASS_UG;
		case 105:
			return MASS_G;
		case 110:
			return MASS_KG;
                case 115:
                        return MASS_OZ;
                case 120:
                        return MASS_LBS;
		default:
			throw new EnumConstantNotPresentException(Units.class, String.valueOf(unit));
		}
	}
        
        public static String getUnitLongDescription(final int unit) {
		switch (unit) {
                case 0:
                        return "Other";
                case 1:
                        return "Each";
                case 10:
			return "Milliliters";
		case 15:
			return "Liters";
		case 20:
			return "Fluid Ounces";
		case 25:
			return "Gallons";
                case 30:
                        return "Barrels";
		case 100:
			return "Micrograms";
		case 105:
			return "Grams";
		case 110:
			return "Kilograms";
                case 115:
                        return "Ounces";
                case 120:
                        return "Pounds";
		default:
			throw new EnumConstantNotPresentException(Units.class, String.valueOf(unit));
		}
	}
        
        public static int getUnitFromShortDescription(final String desc){
            if(desc.equals("mL")){
                return 10;
            } else if(desc.equals("ea")){
			return 1;
            } else if(desc.equals("L")){
			return 15;
            } else if(desc.equals("Fl Oz.")){
			return 20;
            } else if(desc.equals("Gal.")){
			return 25;
            } else if(desc.equals("BBL")){
			return 30;
            } else if(desc.equals("ug")){
			return 100;
            } else if(desc.equals("g")){
			return 105;
            } else if(desc.equals("kg")){
			return 110;
            } else if(desc.equals("Oz.")){
			return 115;
            } else if(desc.equals("Lbs.")){
			return 120;
            } else {
                return 120;
            }
        }
        
        public static List<String> getComboBoxData(){
            List<String> combo = new ArrayList<String>();
            combo.add("Other");
            combo.add("ea");
            combo.add("mL");
            combo.add("L");
            combo.add("Fl Oz.");
            combo.add("Gal.");
            combo.add("BBL");
            combo.add("ug");
            combo.add("g");
            combo.add("kg");
            combo.add("Oz.");
            combo.add("Lbs.");
            return combo;
        }
        
        public static int getUnitFromLongDescription(final String desc){
            if(desc.equals("Milliliters")){
                return 10;
            } else if(desc.equals("Each")){
			return 1;
            } else if(desc.equals("Liters")){
			return 15;
            } else if(desc.equals("Fluid Ounces")){
			return 20;
            } else if(desc.equals("Gallons")){
			return 25;
            } else if(desc.equals("Barrels")){
			return 30;
            } else if(desc.equals("Micrograms")){
			return 100;
            } else if(desc.equals("Grams")){
			return 105;
            } else if(desc.equals("Kilograms")){
			return 110;
            } else if(desc.equals("Ounces")){
			return 110;
            } else if(desc.equals("Pounds")){
			return 115;
            } else {
                return 120;
            }
        }
        
        public static String getUnitShortDescription(final int unit) {
		switch (unit) {
                case 0:
                        return "Other";
                case 1:
                        return "ea";
                case 10:
			return "mL";
		case 15:
			return "L";
		case 20:
			return "Fl Oz.";
		case 25:
			return "Gal.";
                case 30:
                        return "BBL";
		case 100:
			return "ug";
		case 105:
			return "g";
		case 110:
			return "kg";
                case 115:
                        return "Oz.";
                case 120:
                        return "Lbs.";
		default:
			throw new EnumConstantNotPresentException(Units.class, String.valueOf(unit));
		}
	}
        
        public static float convertUnits(final int from, final int to, final float amt){
            double toAmt = 0;
            switch (from) {
                case 0:
                    //Other
                    toAmt = 0;
                case 1:
                    //ea
                    switch(to){
                        //ea
                        case 1:
                            return (float)amt;
                        default:
                            return (float)0;
                    }
                case 10:
                    //mL
                    switch(to){
                        case 15:
                            //L
                            return (float)(amt * 0.001);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 0.033814);
                        case 25:
                            //Gal
                            return (float)(amt * 0.000264172);
                        case 30:
                            //BBL
                            return (float)(amt * 0.000264172 / 31);
                        default:
                            return (float)(amt);
                    }
		case 15:
                    //L
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 1000);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 33.814);
                        case 25:
                            //Gal
                            return (float)(amt * 0.264172);
                        case 30:
                            //BBL
                            return (float)(amt * 0.264172 / 31);
                        default:
                            return (float)(amt);
                    }
		case 20:
                    //Fl Oz.
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 29.5735);
                        case 15:
                            //L
                            return (float)(amt * 0.0295735);
                        case 25:
                            //Gal
                            return (float)(amt * 0.0078125);
                        case 30:
                            //BBL
                            return (float)(amt * 0.0078125 / 31);
                        default:
                            return (float)(amt);
                    }
		case 25:
                    //Gal
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 3785.41);
                        case 15:
                            //L
                            return (float)(amt * 3.78541);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 128);
                        case 30:
                            //BBL
                            return (float)(amt / 31);
                        default:
                            return (float)(amt);
                    }
                case 30:
                    //BBL
                    switch(to){
                        case 10:
                            //mL
                            return (float)(amt * 31 * 3785.41);
                        case 15:
                            //L
                            return (float)(amt * 31 * 3.78541);
                        case 20:
                            //Fl Oz.
                            return (float)(amt * 31 * 128);
                        case 25:
                            //GAL
                            return (float)(amt * 31);
                        default:
                            return (float)(amt);
                    }
                /* Dry Weight Units Next*/
		case 100:
                    //ug
                    switch(to){
                        case 105:
                            //g
                            return (float)(amt * .000001);
                        case 110:
                            //kg
                            return (float)(amt * .000000001);
                        case 115:
                            //Oz.
                            return (float)(amt * .000000035274);
                        case 120:
                            //Lbs
                            return (float)(amt * .0000000022046);
                        default:
                            return (float)(amt);
                    }
		case 105:
                    //g
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 1000000);
                        case 110:
                            //kg
                            return (float)(amt * .001);
                        case 115:
                            //Oz.
                            return (float)(amt * 0.035274);
                        case 120:
                            //Lbs
                            return (float)(amt * 0.00220462);
                        default:
                            return (float)(amt);
                    }
		case 110:
                    //kg
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 1000000000);
                        case 105:
                            //g
                            return (float)(amt * 1000);
                        case 115:
                            //Oz.
                            return (float)(amt * 35.274);
                        case 120:
                            //Lbs
                            return (float)(amt * 2.20462);
                        default:
                            return (float)(amt);
                    }
                case 115:
                    //oz
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 28350000);
                        case 105:
                            //g
                            return (float)(amt * 28.3495);
                        case 110:
                            //kg.
                            return (float)(amt * 0.0283495);
                        case 120:
                            //Lbs
                            return (float)(amt * 0.0625);
                        default:
                            return (float)(amt);
                    }
                case 120:
                    //lbs
                    switch(to){
                        case 100:
                            //ug
                            return (float)(amt * 453600000);
                        case 105:
                            //g
                            return (float)(amt * 453.592);
                        case 110:
                            //kg.
                            return (float)(amt * 0.453592);
                        case 115:
                            //Oz
                            return (float)(amt * 16);
                        default:
                            return (float)(amt);
                    }
		default:
                    return 0;
		}
        }
}
